#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
struct Student{
	char name[105];
	int age;
	int score;	
};
Student stu[1005];
bool cmp(Student a,Student b){
	if(a.score!=b.score){
		return a.score<b.score;
	}else{
		if(strcmp(a.name,b.name)!=0){
			return strcmp(a.name,b.name)<0;
		}else{
			return a.age<b.age;
		}
	}
}
int main(){
	int n;
	while(~scanf("%d",&n)){
		for(int i=0;i<n;i++){
			scanf("%s%d%d",stu[i].name,&stu[i].age,&stu[i].score);
		}
		sort(stu,stu+n,cmp);
		for(int i=0;i<n;i++){
			printf("%s %d %d\n",stu[i].name,stu[i].age,stu[i].score);
		}
	}
	return 0;
}
